#ifndef ZINGME_NETWORK_CONNECTION_H
#define ZINGME_NETWORK_CONNECTION_H

#include "../networkconnection.h"

#include <QSemaphore>


namespace Network {
namespace Zingme {
class Websocket;
class Connection : public Network::Connection
{
    Q_OBJECT
public:
    explicit Connection(QObject *parent = 0);
    virtual ~Connection();

public:
    bool connect(const QString url, unsigned int port, const QVariant &params);
    bool reconnect();
    bool post(ConnectionRequest *request);
    bool isConnected() const;
    bool disconnect();

private:
    void onConnected();
    void onReceived(QByteArray message);
    void onDisconnected();

private:
    bool m_stopped;
    QSemaphore m_locker;
    QSemaphore m_activator;
    QSemaphore m_stopper;

    typedef QList<ConnectionRequest *> Requests;
    Requests m_requests;

    Websocket *m_websocket;
};

} // namespace Zingme

} // namespace Network
#endif // ZINGME_NETWORK_CONNECTION_H
